<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title></title>
	</head>
	<body>
		<script>
			function foo(){
				let arr = [];
				for (let i = 0; i < 10; i++) {
					arr[i] = (function(n){
						return function() {
							return n;
						}
					})(i);
				}
				return arr;
			}
			var bar = foo();
			console.log(bar)
			console.log(bar[0]());
			console.log(bar[1]());
		</script>
	</body>
</html>